package org.joinme.backend.config;

import org.joinme.backend.util.ApiJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

public class LoginFilter extends OncePerRequestFilter {
	Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Override
	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
	    try {
			log.info("--> "+request.getRequestURI());
			Map<String, String[]> params = request.getParameterMap();
			log.info(ApiJson.toJson(params));
		} catch (Exception e) {
			e.printStackTrace();
		}
		filterChain.doFilter(request, response);
	}

}
